package com.campus.admin.controller;


import com.campus.common.core.domain.AjaxResult;
import com.campus.pojos.domain.ClientComment;
import com.campus.pojos.domain.dto.CommentQueryDto;
import com.campus.pojos.domain.vo.CommentVo;
import com.campus.result.Result;
import com.campus.service.CommentService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController(value = "adminCommentController")
@RequestMapping("/system/admin/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;
    @PostMapping("/list")
    public AjaxResult getCommentList(@RequestBody CommentQueryDto dto){
        return commentService.getList(dto);
    }


    /**
     * 删除评论
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Long id){
        commentService.delete(id);
        return AjaxResult.success();
    }

    /**
     * 根据ids删除评论
     * @return
     */
    @DeleteMapping("/deleteBatch")
    public AjaxResult deleteById(@RequestParam(value = "ids",required = false)  List<Integer> ids){
        commentService.removeByIds(ids);
        return AjaxResult.success();
    }

    /**
     * 根据id获取评论
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<CommentVo> getComment(@PathVariable Long id){
        ClientComment comment = commentService.getById(id);
        if(comment == null) return Result.error("id有误");
        CommentVo commentVo = new CommentVo();
        BeanUtils.copyProperties(comment, commentVo);
        return Result.success(commentVo);
    }
}
